<template>
	<view>
		<view class="head">
			<view class="left" @click="goBack"><image src="../../static/stock/left.png" mode=""></image></view>
			<view class="center">物流地址</view>
			<view class="right" @click="pushAdd"><image src="../../static/bu/jia.png" mode=""></image></view>
		</view>
		<view class="box" @click="no">不需要发货地址</view>
		<view class="bad" v-for="(item, index) in address">
			<view class="battop"  @click="goDetails(index)">{{ item }}</view>
			<view class="batbot">
				<view class="left" @click="deletAdd(index)">
					<image src="../../static/bu/delt.png" mode=""></image>
					删除
				</view>
				<view class="left" @click="changeadd(index)">
					<image src="../../static/bu/gai.png" mode=""></image>
					修改
				</view>
			</view>
		</view>
		<uni-popup ref="popup" type="center">
			<view class="addContent">
				<view class="box">
					<view class="tit tCenter f36 c333">请输入物流地址</view>
					<view class="input-box"><input type="text" v-model="name" /></view>
					<view class="btn f30 tCenter">
						<view class="dropBtn" @click="close">取消</view>
						<view class="submit" @click="open">确定</view>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
import uniPopup from '@/components/uni-popup/uni-popup.vue';
export default {
	data() {
		return {
			type:-1,
			name:'',
			add: {},
	       address:[]
		};
	},
	components: {
		uniPopup
	},
	onLoad() {
		this.add=uni.getStorageSync('uat')
	
		// console.log(this.add);
	},
	methods: {
		no(){
			this.$ajax('api/v1.customer/edit',{
			    name:this.add.name,
				customer_id:this.add.customer_id,
				rank_id:this.add.rank_id,
				telephone:this.add.telephone,
				address:''
			       }).then((res)=>{
			      console.log(res);
			       }).catch(res=>{
			        console.log(Error);
			       })
				   uni.navigateTo({
				   	url:'Details'
				   })
		},
	goDetails(e){
		// console.log(this.address[e]);
	this.$ajax('api/v1.customer/edit',{
	    name:this.add.name,
		customer_id:this.add.customer_id,
		rank_id:this.add.rank_id,
		telephone:this.add.telephone,
		address:this.address[e]
	       }).then((res)=>{
	      console.log(res);
	       }).catch(res=>{
	        console.log(Error);
	       })
		   uni.navigateTo({
		   	url:'Details'
		   })
	},
		close() {
			this.$refs.popup.close();
		},
		open() {
	if(this.type==-1){
		this.address.unshift(this.name)
		this.$refs.popup.close();
	

	}else{
		
		this.address[this.type]=this.name
	this.$set(this.address,this.type,this.address[this.type])
			this.$refs.popup.close();
		
	}

			// this.$ajax('/api/v1.customer/edit', {
			// 	customer_id: this.customer_id,
			// 	address: JSON.stringify(this.address),
			// 	name: this.name,
			// 	telephone: this.telephone
			// })
			// 	.then(res => {

			// 	})
			// 	.catch(res => {
			// 		console.log(Error);
			// 	});
		},

	pushAdd(){
		this.type=-1
			this.$refs.popup.open();
	},

	deletAdd(e){
		this.address.splice(e,1)
		this.changeAdress()
	},
goBack(){
	uni.navigateBack({
		delta:1
	})
},
	changeadd(e){
		this.type=e
		this.$refs.popup.open();
	},

	}
};
</script>

<style lang="less">
page {
	background-color: #f7f4f8;
}

.head {
	height: 88rpx;
	display: flex;
	justify-content: space-between;
	background-color: #249af6;
	color: #ffffff;
	padding: 27rpx 30rpx;
	box-sizing: border-box;
	.left {
		image {
			width: 22rpx;
			height: 39rpx;
		}
	}
	.center {
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: 500;
	}
	.right {
		image {
			width: 44rpx;
			height: 44rpx;
		}
	}
}
.box {
	height: 89rpx;
	line-height: 89rpx;
	font-size: 30rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: rgba(102, 102, 102, 1);
	padding-left: 30rpx;
}
.bad {
	margin-bottom: 20rpx;
	background-color: #ffffff;
	padding: 30rpx;
	box-sizing: border-box;
	.battop {
		height: 145rpx;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: rgba(51, 51, 51, 1);
		border-bottom: 3rpx solid #eeeeee;
	}
	.batbot {
		display: flex;
		justify-content: flex-end;
		height: 98rpx;
		.left {
			margin-left: 70rpx;
			line-height: 98rpx;
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: rgba(102, 102, 102, 1);
			image {
				margin-left: 20rpx;
				margin-right: 5rpx;
				width: 30rpx;
				height: 30rpx;
			}
		}
	}
}
.addContent {
	height: 330rpx;
}
// 选择弹出
.chooseBox {
	width: 100%;
	padding-top: 30upx;
	.choose-item {
		width: 100%;
		height: 100%;
		display: flex;
		flex: 1;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		padding: 0 30upx 35upx 30upx;
		margin-bottom: 35upx;
		border-bottom: 2upx #eee solid;
		box-sizing: border-box;
		.arrow {
			image {
				width: 20upx;
				height: 35upx;
			}
		}
	}
}
</style>
